import { ElMessage } from 'element-plus'
import api from '../index'

export default {
  // 新增会议
  create: (data: ConferenceApiTypes.create) => api.post<Resp<number>>('meeting', data),

  // 修改会议信息
  edit: (data: ConferenceApiTypes.edit) => api.put<Resp<number>>('meeting', data),

  // 获取列表
  getList: (query: PageQuery) => api.post<Page<ConferenceApiTypes.list>>(
    `meetingList?page=${query.page}&pageSize=${query.pageSize}`,
    {},
  ),

  // 获取详情
  getDetail: (id: number | string) => api.get<MeetingApiTypes>(`meeting/${id}`),

  // 删除一个会议
  delete: (id: number) => api.delete<Resp<number>>(`meeting/${id}`).then((res) => {
    ElMessage({
      type: 'success',
      message: '删除成功',
    })
    return res
  }),

  start: (id: number) => api.put('/meeting/begin', {
    id,
  }),

  finish: (id: number) => api.put('/meeting/end', {
    id,
  }),

  // 排序议题
  sort: (data: { id: number }[]) => api.post<Resp<void>>('/subject/adjustWeightBatch', data),
}
